#pragma once
#ifndef _CMFT_h_LW_
#define _CMFT_h_LW_

#include <vector>
#include <list>
#include <QString>
#include <QList>
#include <boost/smart_ptr/shared_array.hpp>

#include "Runlist.h"
#include "CAttribute.h"


class VolumeReader;
struct ResidentAttrHdr;
struct NonResidentAttrHdr;

struct StdInfoTime
{
	SYSTEMTIME creation;
	SYSTEMTIME modify;
	SYSTEMTIME entry;
	SYSTEMTIME access;

 };

typedef StdInfoTime FileNameTime;



/**
 * store all 8 timestamps of a MFT
 */
struct NTFSFileTime {
	StdInfoTime stdInfoTime;
	FileNameTime fileNameTime;
};

struct RecycleSupport;

class CMFT
{	
public:
	CMFT(VolumeReader *parent=0,UINT64 startByte=0)
		:parentVR(parent),diskOffSet(startByte),recycle(0) {};
	~CMFT(void);
	QString getFileName() const;
	UINT64 getAttPos( int attrType, int attrId, UINT64 startByte );
	int countAttr(int attrType);
	bool hasExisted();
	bool isBase();
	UINT64 entryNo() ;
	//************************************
	// Returns:   NTFSFileTime : time information in Both FileNameAttr and StdInfoAttr
	//************************************
	NTFSFileTime getTimes();

	UINT64 getBaseRef();
	void combineRunList( int attrType, int attrId, RunList runList );
	bool hasAttr( int attrType,int attrId );
	QString getPath();
	UINT64 getParentRef();
	//must be called *after* getPath()
	bool isOrphan();
	UINT64 getFileRef();
	CAttribute getAttribute(int attrType,int id);
	CAttribute getAttribute(int attrType);
	bool isDeleted();
	void append( CMFT & child );
	QList<Range> getCollision( CMFT * other );
	bool haveTimes();
	QString getFileNameExtension();
	bool isDirectory();
	CMFT getParentDir();
	UINT64 getLSN();
	//HACK:public data EVIL!!!
	VolumeReader * parentVR;
	UINT64 diskOffSet;
	//set when getpath() is invoked
	bool _isOrphan;
#pragma region MFTData_derived
	//
	//data calculated from | mftData
	QList<ResidentAttrHdr*> resAttrs;
	QList<NonResidentAttrHdr*> nresAttrs;
	QList<RunList> runLists;
	QList<boost::shared_array<char>> mftData;
	RecycleSupport * recycle;
#pragma endregion 
};

#endif // _CMFT_h_LW_
